﻿
import os

# 列表生成式即List Comprehensions，是Python内置的非常简单却强大的可以用来创建list的生成式

print "range(1,11) =",range(1,11)

L=[]
print "L =",L
for x in range(1,11):
	L.append(x*x)
print "L =",L

print "[x*x for x in range(1,11)] =",[x*x for x in range(1,11)]
print "[x*x for x in range(1,11) if x%2 == 0] =",[x*x for x in range(1,11) if x%2 == 0]
print "[m+n for m in 'ABC' for n in 'XYZ'] =",[m+n for m in 'ABC' for n in 'XYZ']

print "[d for d in os.listdir('.')] =",[d for d in os.listdir('.')]

d={'x':'A','y':'B','z':'C'}
print "d =",d
for k,v in d.iteritems():
	print "key =",k,"  value =",v

print "[k+'='+v for k,v in d.iteritems()] =",[k+'='+v for k,v in d.iteritems()]

L=['Hello','World','IBM','Apple']
print "L =",L
print "[s.lower() for s in L] =",[s.lower() for s in L]